package com.laputacastle.dr.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.laputacastle.dr.mapper.DemoRecordMapper;
import com.laputacastle.dr.model.DemoRecord;
import com.laputacastle.dr.service.DemoRecordService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.UUID;
@Service
public class DemoRecordServiceImpl implements DemoRecordService {

    @Autowired
    private DemoRecordMapper demoRecordMapper;

    @Override
    public int insertSelective(JSONObject obj) {
        DemoRecord demoRecord =  DemoRecord.builder()
                .cId(UUID.randomUUID().toString().replace("-", ""))
                .cTitle(obj.getString("title"))
                .cDemoMd(obj.getString("saveContext"))
                .cDemoHtml(obj.getString("saveContextHtml"))
                .nCode(StringUtils.isNotBlank(obj.getString("sign")) ? Integer.parseInt(obj.getString("sign")) : 0)
                .dtCreateTime(new Date())
                .dtUpdateTime(new Date())
                .build();
        return demoRecordMapper.insertSelective(demoRecord);
    }
}
